import axios, { AxiosInstance, AxiosRequestConfig, AxiosPromise,AxiosResponse } from 'axios';
// import axios from 'axios'
import * as _ from 'lodash'
import {App} from 'vue'

//http://rap2api.taobao.org/app/mock/279811/service/app/list
const config:AxiosRequestConfig = {
  baseURL: '',
  headers: { 'content-type': 'application/json' }
}

const install = function(vue: App, options: any){
  new Http(options);
}

class Http {

  static instance: AxiosInstance;

  constructor(options:AxiosRequestConfig){
    Http.instance = axios.create(Object.assign(config, options));
  }

  static getInstance(options:AxiosRequestConfig = {}){
    if(Http.instance == null || !_.isEmpty(options)){
      Http.instance = axios.create(Object.assign(config, options));
    }
    return Http.instance
  }

  static install = install
}



export const useHttp  = Http.getInstance;

export default Http;